
export class LogLevel {

    off = 0
    error = 1
    warn = 2
    debug = 3
    info = 4
    all = 5

}
const logLevel = new LogLevel();
interface Log4RConfig {
    level: keyof LogLevel
    productLevel: keyof LogLevel
}
const config = require(game.GetService('ReplicatedFirst').WaitForChild('logconfig') as ModuleScript) as Log4RConfig
const configlevel = logLevel[config.level] || 0
const isStudio = game.GetService('RunService').IsStudio();
export default class Log4R {
    static getLog(level: keyof LogLevel) {
        if (isStudio && logLevel[level] && (logLevel[level] <= logLevel[config.level])) {
            return log
        } else {
            if (logLevel[level] && (logLevel[level] <= logLevel[config.productLevel])) {
                return log
            }
        }

    }
    private log(params: unknown[], level: string) {
        const traceback = debug.traceback('log');
        const line = traceback.split('\n')[3];
        // print('x', x)
        const logcontent = [
            level, line, { traceback }, '\n>>>>>>', ...params
        ]
        print(...logcontent)
    }
    all(...params: unknown[]) {
        if (configlevel >= logLevel.all) {
            this.log(params, 'all')
        }
    }
    debug(...params: unknown[]) {
        if (configlevel >= logLevel.debug) {
            this.log(params, 'debug')
        }
    }
    info(...params: unknown[]) {
        if (configlevel >= logLevel.info) {
            this.log(params, 'info')
        }
    }
    warn(...params: unknown[]) {
        if (configlevel >= logLevel.warn) {
            this.log(params, 'warn')
        }
    }
    error(...params: unknown[]) {
        if (configlevel >= logLevel.error) {
            this.log(params, 'error')
        }
    }
}
const log = new Log4R()
const logLog4r = Log4R.getLog('all');
logLog4r?.info('<----------------log4R-----------------')
logLog4r?.info('log level', config.level)
logLog4r?.info('log productLevel', config.productLevel)
logLog4r?.info('----------------log4R----------------->')